<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="layout.xhtml">
        
        <ui:define name="title">
            Registro de Imóveis
        </ui:define>        
        
        <ui:define name="content">
            <h:form id="registroImovelForm" enctype="multipart/form-data">
                         <div class="actions">
                    <div id="buttons">
                        <p:button value="Editar" outcome="criarImovel.xhtml"
                                  rendered="#{ managerPesquisarImovel.imovelVisualizar.id != null }"
                                  icon="ui-icon-pencil"
                                  styleClass="ui-priority-primary">
                            <f:param value="#{ managerPesquisarImovel.imovelVisualizar.id }" name="imovelId"/>
                        </p:button>

                        <p:splitButton value="Ações" process="@none" icon="ui-icon-gear" styleClass="acoes">
                            <f:param value="#{ managerPesquisarImovel.imovelVisualizar.id }" name="imovelId"/>

                            <p:separator />

                            <p:menuitem value="Averbar" icon="ui-icon-clipboard" outcome="fazerAverbacao.xhtml" >  
                                <f:param name="imovelId" value="#{ managerPesquisarImovel.imovelVisualizar.id }"/>
                            </p:menuitem>

                            <p:menuitem value="Registrar" icon="ui-icon-plus" outcome="fazerRegistro.xhtml" >
                                <f:param name="imovelId" value="#{ managerPesquisarImovel.imovelVisualizar.id }"/>
                            </p:menuitem>                            

                            <p:menuitem value="Transferir" icon="ui-icon-refresh" outcome="fazerTransferencia.xhtml" >  
                                <f:param name="imovelId" value="#{ managerPesquisarImovel.imovelVisualizar.id }"/>
                            </p:menuitem>

                            <p:menuitem value="Emitir Matrícula" title="Emitir Matrícula" icon="ui-icon-clipboard" 
                                        ajax="false" actionListener="#{ managerPesquisarImovel.emitirMatricula() }">
                            </p:menuitem>

                            <p:menuitem value="Excluir" title="Excluir" oncomplete="dialogApagar.show()" icon="ui-icon-trash">
                                <f:setPropertyActionListener target="#{ managerPesquisarImovel.imovelDeletar }" value="#{ imovel }" />
                            </p:menuitem>

                        </p:splitButton>                     

                    </div>
                </div>

                <p:messages id="fazerRegistroMessages" autoUpdate="true" />                 

                <p:fieldset legend="Dados do Registro">

                    <div class="row">
                        <div class="column2">
                            <p:outputLabel value="Número" for="numeroInputText" />
                        </div>
                        <div class="column3">
                            <p:inputText id="numeroInputText" value="#{ managerRegistroImovel.registro.numero }"
                                readonly="true"
                                onkeypress="jQuery(this).autoNumeric({aSep: '', aDec: ',', vMin:0, wEmpty: '0', mDec: 0});"
                                requiredMessage="Número é obrigatório" required="true" />
                        </div>

                        <div class="column2">
                            <p:outputLabel value="Data do Registro" for="descricaoInputTextarea" />
                        </div>
                        <div class="column3">
                            <p:calendar id="dataVigorCalendar" value="#{ managerRegistroImovel.registro.dataRegistro }"
                                showOn="button" pattern="dd/MM/yyyy" locale="pt" navigator="true" required="true"
                                requiredMessage="Data da Registro é obrigatório" />
                        </div>
                    </div>                            

                    <div class="row">
                        <div class="column2">
                            <p:outputLabel value="Tipo" for="tipoAtoImovelAutoComplete" />
                        </div>
                        <div class="column8">
                            <p:autoComplete id="tipoAtoImovelAutoComplete" value= "#{ managerRegistroImovel.registro.tipoAtoImovel }"
                                            forceSelection="true" dropdown="true" var="tipoAtoImovel" itemValue= "#{ tipoAtoImovel }" 
                                            itemLabel= "#{ tipoAtoImovel.descricao }" completeMethod= "#{ managerRegistroImovel.autocompletarTipoAtoImovel }"
                                            converter="conversortipoatoimovel" minQueryLength="3">
                            </p:autoComplete>
                        </div>
                    </div>                    
                    
                    <div class="row">
                        <div class="column2">
                            <p:outputLabel value="Descrição" for="descricaoInputTextarea" />
                        </div>
                        <div class="column8">
                            <p:inputTextarea id="descricaoInputTextarea"
                                value="#{ managerRegistroImovel.registro.descricao }"
                                requiredMessage="Descrição é obrigatório" required="true" />
                        </div>
                    </div>

                </p:fieldset>

                <div class="command">
                    <p:commandButton actionListener="#{ managerRegistroImovel.registrar() }"
                        styleClass="ui-priority-primary" oncomplete="widthFix();"  onsuccess="goY(0);"
                        value="Registrar" update="@form" icon="ui-icon-disk" />
                    <p:button value="Voltar" icon="ui-icon-arrowreturn-1-w" href="visualizarImovel.xhtml?imovelId=#{ managerAverbacaoImovel.imovel.id }" />
                </div>                      

            </h:form>
                
        </ui:define>
    </ui:composition>
</html>
